package com.kws.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kws.common.core.domain.R;
import com.kws.system.domain.vo.QueryOperLogRq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.kws.common.core.utils.poi.ExcelUtil;
import com.kws.common.log.annotation.Log;
import com.kws.common.log.enums.BusinessType;
import com.kws.common.security.annotation.InnerAuth;
import com.kws.common.security.annotation.RequiresPermissions;
import com.kws.system.api.domain.SysOperLog;
import com.kws.system.service.ISysOperLogService;

/**
 * 操作日志记录
 * 
 * @author zhangyh
 */
@RestController
@RequestMapping("/operlog")
@Api(tags = "日志管理模块")
public class SysOperlogController
{
    @Autowired
    private ISysOperLogService operLogService;

//    @RequiresPermissions("system:operlog:list")
    @PostMapping("/list")
    @ApiOperation("分页查询日志列表")
    public R<Page<SysOperLog>> list(@RequestBody QueryOperLogRq rq)
    {
        Page<SysOperLog> pageInfo = operLogService.queryOerLogPage(rq);
        return R.ok(pageInfo);
    }

//    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
////    @RequiresPermissions("system:operlog:export")
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, SysOperLog operLog)
//    {
//        List<SysOperLog> list = operLogService.selectOperLogList(operLog);
//        ExcelUtil<SysOperLog> util = new ExcelUtil<SysOperLog>(SysOperLog.class);
//        util.exportExcel(response, list, "操作日志");
//    }

    @Log(title = "删除日志", businessType = BusinessType.DELETE)
//    @RequiresPermissions("system:operlog:remove")
    @ApiOperation("根据操作日志ID删除操作日志详情")
    @GetMapping("/delete/{operIds}")
    public R remove(@PathVariable Long[] operIds)
    {
        return R.ok(operLogService.deleteOperLogByIds(operIds));
    }


    @ApiOperation("根据日志ID查询日志详情")
    @GetMapping("/query/operLog/byId")
    public R<SysOperLog> queryOperLogById(@RequestParam Long operId){
        SysOperLog info = operLogService.queryOperLogById(operId);
        return R.ok(info);
    }

//    @RequiresPermissions("system:operlog:remove")
//    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
//    @GetMapping("/clean")
//    public R clean()
//    {
//        operLogService.cleanOperLog();
//        return R.ok();
//    }

    @InnerAuth
    @PostMapping
    public R add(@RequestBody SysOperLog operLog)
    {
        return R.ok(operLogService.insertOperlog(operLog));
    }
}
